/*
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/*
 * @(#)RSMetaClient.java	1.15 02/01/12
 */

package jdbcts.rsMeta;

import java.io.*;
import java.util.*;

import java.sql.*;
import javax.sql.*;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.sun.cts.util.*;
import com.sun.cts.porting.*;
import com.sun.cts.harness.*;

import java.rmi.RemoteException;

import javasoft.sqe.javatest.Status;
import jdbcts.SuperTest;
import jdbcts.common.DataSourceConnection;
import jdbcts.common.DriverManagerConnection;
import jdbcts.common.dbSchema;

import com.sun.cts.tests.jdbc.ee.common.*;

// Merant DataSource class
//import com.merant.sequelink.jdbcx.datasource.*;

/**
 * The RSMetaClient class tests methods of ResultSetMetaData interface using
 * Sun's J2EE Reference Implementation.
 * 
 * @author
 * @version 1.7, 06/16/99
 */

public class RSMetaClient extends SuperTest implements Serializable
{
    private static final String testName = "jdbc.ee.rsMeta";

    // Naming specific member variables
    private CTSNamingContextInterface jc = null;

    // Harness requirements

    private transient static Connection coffeeCon = null;

    private DataSource ds1 = null;

    private static dbSchema dbSch = null;

    private static String drManager = null;

    private static String query = null;

    private static ResultSet rs = null;

    private static ResultSetMetaData rsmd = null;

    private static Statement stmt = null;

    /* private String sqlStmt=null; */

    /* Run test in standalone mode */
    // public static void main(String[] args)
    // {
    // RSMetaClient theTests = new RSMetaClient();
    // Status s=theTests.run(args, System.out, System.err);
    // s.exit();
    // }

    /* Test setup: */
    /*
     * @class.setup_props: Driver, the Driver name; db1, the database name with
     * url; user1, the database user name; password1, the database password;
     * db2, the database name with url; user2, the database user name;
     * password2, the database password; DriverManager, flag for DriverManager;
     * ptable, the primary table; ftable, the foreign table; cofSize, the
     * initial size of the ptable; cofTypeSize, the initial size of the ftable;
     * binarySize, size of binary data type; varbinarySize, size of varbinary
     * data type; longvarbinarySize, size of longvarbinary data type;
     * 
     * @class.testArgs: -ap ctssql.stmt
     */
    @BeforeClass
    // public void setup(String[] args, Properties p) throws Exception
    public static void setup() throws Exception
    {
	try
	{
	    try
	    {
		/*
		 * sqlStmt= p.getProperty("rsQuery",""); InputStream istr= new
		 * FileInputStream(sqlStmt); Properties sqlp=new Properties();
		 * sqlp.load(istr); query=sqlp.getProperty("selectCoffee","");
		 */

		// String fTableName = p.getProperty("ftable","");
		// query = "SELECT COF_NAME, PRICE FROM " + fTableName;
		query = queryAll;

		if (query.length() == 0)
		    throw new Exception("Invalid SQL Statement ");
		logMsg("SQL Statement : " + query);

		// drManager = p.getProperty("DriverManager","");
		drManager = isDRManager;
		if (drManager.length() == 0)
		    throw new Exception("Invalid DriverManager Name");

		if (drManager.equals("yes"))
		{
		    logMsg("Using DriverManager");
		    DriverManagerConnection dmCon = new DriverManagerConnection();
		    // coffeeCon = dmCon.getConnection(p);
		    coffeeCon = dmCon.getConnection(null);
		    dbSch = new dbSchema();
		    // dbSch.createData(p,coffeeCon);
		    // Since scrollable resultSet is optional, the parameters
		    // are
		    // commented out.
		    stmt = coffeeCon.createStatement(/*
						      * ResultSet.TYPE_SCROLL_INSENSITIVE
						      * ,
						      * ResultSet.CONCUR_READ_ONLY
						      */);
		    rs = stmt.executeQuery(query);
		    rsmd = rs.getMetaData();
		}
		else
		{
		    logMsg("Using DataSource");
		    DataSourceConnection dsCon = new DataSourceConnection();
		    // coffeeCon = dsCon.getConnection(p);
		    coffeeCon = dsCon.getConnection(null);
		    dbSch = new dbSchema();
		    // dbSch.createData(p,coffeeCon);
		    // Since scrollable resultSet is optional, the parameters
		    // are
		    // commented out.
		    stmt = coffeeCon.createStatement(/*
						      * ResultSet.TYPE_SCROLL_INSENSITIVE
						      * ,
						      * ResultSet.CONCUR_READ_ONLY
						      */);
		    rs = stmt.executeQuery(query);
		    rsmd = rs.getMetaData();
		}
	    }
	    catch (SQLException ex)
	    {
		logErr("SQL Exception : " + ex.getMessage());
	    }
	}
	catch (Exception e)
	{
	    logErr("Setup Failed!");
	    TestUtil.printStackTrace(e);
	}
    }

    /*
     * @testName: testGetColumnCount
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition) A driver must provide full
     * support for DatabaseMetaData and ResultSetMetaData. This implies that all
     * of the methods in the ResultSetMetaData interface must be implemented and
     * must behave as specified in the JDBC 1.0 and 2.0 specifications. None of
     * the methods in DatabaseMetaData and ResultSetMetaData may throw an
     * exception because they are not implemented. (See section 6.2.2.3 of Java2
     * Platform Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getColumnCount method returns an integer value representing the
     * number of columns in the ResultSet object.for which this
     * ResultSetMetaData object stores information. (See Section 27.3 of JDBC
     * 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getColumnCount() method on the ResultSetMetaData object.It should return
     * an integer value greater than or equal to zero.
     */
    @Test
    public void testGetColumnCount() throws Exception
    {
	try
	{
	    // invoke on the getColumnCount
	    logMsg("Calling getColumnCount on ResultSetMetaData");
	    int coloumnCount = rsmd.getColumnCount();
	    if (coloumnCount >= 0)
	    {
		logMsg("getColumnCount method returns: " + coloumnCount);
	    }
	    else
	    {
		logErr(" getColumnCount method returns a negative value");

	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getColumnCount is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getColumnCount is Failed!", e);
	}
    }

    /*
     * @testName: testIsAutoIncrement
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The isAutoIncrement(int colindex) method returns a boolean value; true if
     * the column colindex is automatically numbered which makes the column
     * read-only and false otherwise. (See Section 27.3 of JDBC 2.0 API
     * Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * isAutoIncrement(int column) method.It should return a boolean value.
     */
    @Test
    public void testIsAutoIncrement() throws Exception
    {
	try
	{
	    // invoke on the isAutoIncrement(int column)
	    logMsg("Calling isAutoIncrement on ResultSetMetaData");
	    boolean retValue = rsmd.isAutoIncrement(1);
	    if (retValue)
	    {
		logMsg("isAutoIncrement method returns column is automatically numbered");
	    }
	    else
	    {
		logMsg("isAutoIncrement method returns column cannot be automatically numbered");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to isAutoIncrement is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to isAutoIncrement is Failed!", e);
	}
    }

    /*
     * / @testName: testIsCaseSensitive
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The isCaseSensitive(int colindex) method returns a boolean value; true if
     * the column colindex is case sensitive and false otherwise. (See Section
     * 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * isCaseSensitive(int column) method.It should return a boolean value.
     */
    @Test
    public void testIsCaseSensitive() throws Exception
    {
	try
	{
	    // invoke on the isCaseSensitive(int column)
	    logMsg("Calling isCaseSensitive on ResultSetMetaData");
	    boolean retValue = rsmd.isCaseSensitive(1);
	    if (retValue)
	    {
		logMsg("isCaseSensitive method returns column's are case sensitive");
	    }
	    else
	    {
		logMsg("isCaseSensitive method returns column's are case insensitive");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to isCaseSensitive is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to isCaseSensitive is Failed!", e);
	}
    }

    /*
     * @testName: testIsSearchable
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The isSearchable(int colindex) method returns a boolean value; true if
     * the value stored in column colindex can be used in a WHERE clause and
     * false otherwise. (See Section 27.3 of JDBC 2.0 API Reference & Tutorial
     * 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * isSearchable(int column) method.It should return a boolean value.
     */
    @Test
    public void testIsSearchable() throws Exception
    {
	try
	{
	    // invoke on the isSearchable(int column)
	    logMsg("Calling isSearchable on ResultSetMetaData");
	    boolean retValue = rsmd.isSearchable(1);
	    if (retValue)
	    {
		logMsg("isSearchable method returns column can be used in a where clause");
	    }
	    else
	    {
		logMsg("isSearchable method returns column cannot be used in a where clause");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to isSearchable is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to isSearchable is Failed!", e);
	}
    }

    /*
     * @testName: testIsCurrency
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The isCurrency(int colindex) method returns a boolean value; true if the
     * column colindex is a cash value and false otherwise. (See Section 27.3 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * isCurrency(int column) method.It should return a boolean value.
     */
    @Test
    public void testIsCurrency() throws Exception
    {
	try
	{
	    // invoke on the isCurrency(int column)
	    logMsg("Calling IsCurrency on ResultSetMetaData");
	    // boolean retValue=rsmd.isCurrency(2);
	    boolean retValue = rsmd.isCurrency(1);
	    if (retValue)
	    {
		logMsg("isCurrency method returns column is a cash value");
	    }
	    else
	    {
		logMsg("isCurrency method returns column does not contains a cash value");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to isCurrency is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to isCurrency is Failed!", e);
	}
    }

    /*
     * @testName: testIsNullable
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The isNullable(int colindex) method returns an integer value the possible
     * values are columnNoNulls, columnNullable and columnNullableUnknown. (See
     * Section 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * isNullable(int column) method.It should return an integer value which is
     * one of the constants columnNoNulls(0),columnNullable(1) and
     * columnNullableUnknown(2).
     */
    @Test
    public void testIsNullable() throws Exception
    {
	try
	{
	    // invoke on the isNullable(int column)
	    logMsg("Calling isNullable on ResultSetMetaData");
	    // int coloumnCount=rsmd.isNullable(2);
	    int coloumnCount = rsmd.isNullable(1);
	    if ((coloumnCount == ResultSetMetaData.columnNoNulls)
		    || (coloumnCount == ResultSetMetaData.columnNullable)
		    || (coloumnCount == ResultSetMetaData.columnNullableUnknown))
	    {
		logMsg("isNullable method returns: " + coloumnCount);
	    }
	    else
	    {
		logErr(" isNullable method returns a negative value");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to isNullable is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to isNullable is Failed!", e);
	}
    }

    /*
     * @testName: testIsSigned
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The isSigned(int colindex) method returns a boolean value; true if the
     * value stored in column colindex is a signed number and false otherwise.
     * (See Section 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * isSigned(int column) method.It should return a boolean value.
     */
    @Test
    public void testIsSigned() throws Exception
    {
	try
	{
	    // invoke on the isSigned(int column)
	    logMsg("Calling isSigned on ResultSetMetaData");
	    // boolean retValue=rsmd.isSigned(2);
	    boolean retValue = rsmd.isSigned(1);
	    if (retValue)
	    {
		logMsg("isSigned method returns values in the column are signed numbers");
	    }
	    else
	    {
		logMsg("isSigned method returns values in the column are unsigned numbers");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to isSigned is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to isSigned is Failed!", e);
	}
    }

    /*
     * @testName: testGetColumnDisplaySize
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications.None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getColumnDisplaySize(int colindex) method returns an int value
     * representing the maximum width in characters. (See Section 27.3 of JDBC
     * 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getColumnDisplaySize(int colindex) method.It should return an integer
     * representing the normal maximum width in characters for column colindex.
     */
    @Test
    public void testGetColumnDisplaySize() throws Exception
    {
	try
	{
	    // invoke on the getColumnDisplaySize(int column)
	    logMsg("Calling getColumnDisplaySize on ResultSetMetaData");
	    // int colDispSize=rsmd.getColumnDisplaySize(2);
	    int colDispSize = rsmd.getColumnDisplaySize(1);
	    if (colDispSize >= 0)
	    {
		logMsg("getColumnDisplaySize method returns: " + colDispSize);
	    }
	    else
	    {
		logErr(" getColumnDisplaySize method returns a negative value");

	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getColumnDisplaySize is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getColumnDisplaySize is Failed!", e);
	}
    }

    /*
     * @testName: testGetColumnLabel
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getColumnLabel(int colindex) method returns a String object
     * representing the suggested title for use in printouts and displays. (See
     * Section 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getColumnLabel(int colindex) method.It should return a String object.
     */
    @Test
    public void testGetColumnLabel() throws Exception
    {
	try
	{
	    // invoke on the getColumnLabel(int column)
	    logMsg("Calling getColumnLabel on ResultSetMetadata");
	    // String sRetValue = rsmd.getColumnLabel(2);
	    String sRetValue = rsmd.getColumnLabel(1);
	    if (sRetValue == null)
	    {
		logMsg("getColumnLabel method does not returns the suggested column title");
	    }
	    else
	    {
		logMsg("getColumnLabel method returns:  " + sRetValue);
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getColumnLabel is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getColumnLabel is Failed!", e);
	}
    }

    /*
     * @testName: testGetColumnName
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getColumnName(int colindex) method returns a String object
     * representing the column name (See JDK 1.2.2 API documentation) (See
     * Section 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getColumnName(int colindex) method.It should return a String object.
     */
    @Test
    public void testGetColumnName() throws Exception
    {
	try
	{
	    // invoke on the getColumnName(int column)
	    logMsg("Calling getColumnName on ResultSetMetadata");
	    // String sRetValue = rsmd.getColumnName(2);
	    String sRetValue = rsmd.getColumnName(1);
	    if (sRetValue == null)
	    {
		logMsg("getColumnName method does not returns the column name");
	    }
	    else
	    {
		logMsg("getColumnName method returns:  " + sRetValue);
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getColumnName is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getColumnName is Failed!", e);
	}
    }

    /*
     * @testName: testGetSchemaName
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getSchemaName(int colindex) method returns a String object
     * representing the schema name or an empty string ("") if the DBMS.does not
     * support this feature. (See Section 27.3 of JDBC 2.0 API Reference &
     * Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getSchemaName(int colindex) method.It should return a String object.
     */
    @Test
    public void testGetSchemaName() throws Exception
    {
	try
	{
	    // invoke on the getSchemaName(int column)
	    logMsg("Calling getSchemaName on ResultSetMetadata");
	    // String sRetValue = rsmd.getSchemaName(2);
	    String sRetValue = rsmd.getSchemaName(1);
	    if (sRetValue == null)
	    {
		logMsg("getSchemaName method does not returns the schema name ");
	    }
	    else
	    {
		logMsg("getSchemaName returns:  " + sRetValue);
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getSchemaName is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getSchemaName is Failed!", e);
	}
    }

    /*
     * @testName: testGetPrecision
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getPrecision(int colindex) method returns an integer value
     * representing the number of decimal digits for number types,maximum length
     * in characters for character types,maximum length in bytes for JDBC binary
     * datatypes. (See Section 27.3 of JDBC 2.0 API Reference & Tutorial 2nd
     * edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getPrecision(int colindex) method.It should return an integer greater
     * than or equal to zero.
     */
    @Test
    public void testGetPrecision() throws Exception
    {
	try
	{
	    // invoke on the getPrecision(int column)
	    logMsg("Calling getPrecision on ResultSetMetaData");
	    int precisionSize = rsmd.getPrecision(1);
	    if (precisionSize >= 0)
	    {
		logMsg("getPrecision method returns: " + precisionSize);
	    }
	    else
	    {
		logErr(" getPrecision method returns a negative value");

	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getPrecision is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getPrecision is Failed!", e);
	}
    }

    /*
     * @testName: testGetScale
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getScale(int colindex) method returns an integer value representing
     * the number of digits to right of the decimal point. (See Section 27.3 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getScale(int colindex) method.It should return an integer greater than or
     * equal to zero.
     */
    @Test
    public void testGetScale() throws Exception
    {
	try
	{
	    // invoke on the getScale(int column)
	    logMsg("Calling getScale on ResultSetMetaData");
	    // int scaleSize=rsmd.getScale(2);
	    int scaleSize = rsmd.getScale(1);
	    if (scaleSize >= 0)
	    {
		logMsg("getScale method returns: " + scaleSize);
	    }
	    else
	    {
		logErr(" getScale method returns a negative value");

	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getScale is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getScale is Failed!", e);
	}
    }

    /*
     * @testName: testGetTableName
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getTableName(int colindex) method returns a String object
     * representing the table name or an empty string ("") if the DBMS does not
     * support this feature. (See Section 27.3 of JDBC 2.0 API Reference &
     * Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getTableName(int colindex) method.It should return a String object.
     */
    @Test
    public void testGetTableName() throws Exception
    {
	try
	{
	    // invoke on the getTableName(int column)
	    logMsg("Calling getTableName on ResultSetMetadata");
	    String sRetValue = rsmd.getTableName(1);
	    if (sRetValue == null)
	    {
		logMsg("getTableName method does not returns the column's table name");
	    }
	    else
	    {
		logMsg("getTableName method returns:  " + sRetValue);
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getTableName is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getTableName is Failed!", e);
	}
    }

    /*
     * @testName: testGetCatalogName
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getCatalogName(int colindex) method returns a String object
     * representing the catalog name or an empty string ("") if not applicable.
     * (See Section 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getCatalogName(int colindex) method.It should return a String object.
     */
    @Test
    public void testGetCatalogName() throws Exception
    {
	try
	{
	    // invoke on the getCatalogName(int column)
	    logMsg("Calling getCatalogName on ResultSetMetadata");
	    String sRetValue = rsmd.getCatalogName(1);
	    if (sRetValue == null)
	    {
		logMsg("getCatalogName method does not returns the column's table's catalog name");
	    }
	    else
	    {
		logMsg("getCatalogName method returns:  " + sRetValue);
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getCatalogName is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getCatalogName is Failed!", e);
	}
    }

    /*
     * @testName: testGetColumnType
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getColumnType(int colindex) method returns the JDBC type from the
     * java.sql.Types class for the value in the designated column colindex.
     * (See section 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getColumnType(int colindex) method.Check if an integer value is returned.
     */
    @Test
    public void testGetColumnType() throws Exception
    {
	try
	{
	    // invoke on the getColumnType(int column)
	    logMsg("Calling getColumnType on ResultSetMetaData");
	    int colType = rsmd.getColumnType(1);

	    switch (colType)
	    {
		case Types.BIT:
		case Types.TINYINT:
		case Types.SMALLINT:
		case Types.INTEGER:
		case Types.BIGINT:
		case Types.FLOAT:
		case Types.REAL:
		case Types.DOUBLE:
		case Types.NUMERIC:
		case Types.DECIMAL:
		case Types.CHAR:
		case Types.VARCHAR:
		case Types.LONGVARCHAR:
		case Types.DATE:
		case Types.TIME:
		case Types.TIMESTAMP:
		case Types.BINARY:
		case Types.VARBINARY:
		case Types.LONGVARBINARY:
		case Types.NULL:
		case Types.OTHER:
		case Types.JAVA_OBJECT:
		case Types.DISTINCT:
		case Types.STRUCT:
		case Types.ARRAY:
		case Types.BLOB:
		case Types.CLOB:
		case Types.REF:
		case Types.SQLXML: // Yolanda add(05/24/2010)
		    logMsg("getColumnType method returns: " + colType);
		    break;
		default:
		    logErr(" getColumnType method returns a illegal value");
		    throw new Exception("Call to getColumnTypeName failed !");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getColumnType is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getColumnType is Failed!", e);
	}
    }

    /*
     * @testName: testGetColumnTypeName
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getColumnTypeName(int colindex) method returns a String object
     * representing the type name used by the database. (See section 27.3 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getColumnTypeName(int colindex) method.It should return a String object.
     */
    @Test
    public void testGetColumnTypeName() throws Exception
    {
	try
	{
	    // invoke on the getColumnTypeName(int column)
	    logMsg("Calling getColumnTypeName on ResultSetMetadata");
	    String sRetValue = rsmd.getColumnTypeName(1);
	    if (sRetValue == null)
	    {
		logMsg("getColumnTypeName method does not returns the type name used by the database ");
	    }
	    else
	    {
		logMsg("getColumnTypeName method returns:  " + sRetValue);
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getColumnTypeName is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getColumnTypeName is Failed!", e);
	}
    }

    /*
     * /
     * 
     * @testName: testIsReadOnly
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The isReadOnly(int colindex) method returns a boolean value; true if the
     * column colindex is definitely not writable and false otherwise. (See
     * Section 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * isReadOnly(int column) method.It should return a boolean value.
     */
    @Test
    public void testIsReadOnly() throws Exception
    {
	try
	{
	    // invoke on the isReadOnly(int column)
	    logMsg("Calling isReadOnly on ResultSetMetaData");
	    boolean retValue = rsmd.isReadOnly(1);
	    if (retValue)
	    {
		logMsg("isReadOnly method returns column cannot be writable");
	    }
	    else
	    {
		logMsg("isReadOnly method returns column can be writable");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to isReadOnly is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to isReadOnly is Failed!", e);
	}
    }

    /*
     * @testName: testIsWritable
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The isWritable(int colindex) method returns a boolean value; true if the
     * column colindex is possible for write and false otherwise. (See Section
     * 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * isWritable(int column) method.It should return a boolean value.
     */
    @Test
    public void testIsWritable() throws Exception
    {
	try
	{
	    // invoke on the isWritable(int column)
	    logMsg("Calling isWritable on ResultSetMetaData");
	    boolean retValue = rsmd.isWritable(1);
	    if (retValue)
	    {
		logMsg("isWritable method returns column is writable");
	    }
	    else
	    {
		logMsg("isWritable method returns column cannot be writable");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to isWritable is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to isWritable is Failed!", e);
	}
    }

    /*
     * /
     * 
     * @testName: testIsDefinitelyWritable
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The isDefinitelyWritable(int colindex) method returns a boolean value;
     * true if the write on column colindex will definitely succeed and false
     * otherwise. (See JDK 1.2.2 API documentation) (See Section 27.3 of JDBC
     * 2.0 API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * isDefinitelyWritable(int column) method.It should return a boolean value.
     */
    @Test
    public void testIsDefinitelyWritable() throws Exception
    {
	try
	{
	    // invoke on the isDefinitelyWritable(int column)
	    logMsg("Calling isDefinitelyWritable on ResultSetMetaData");
	    boolean retValue = rsmd.isDefinitelyWritable(1);
	    if (retValue)
	    {
		logMsg("isDefinitelyWritable method returns write on the column is definitely succeed");
	    }
	    else
	    {
		logMsg("isDefinitelyWritable method returns write on the column is definitely failed");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to isDefinitelyWritable is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to isDefinitelyWritable is Failed!", e);
	}
    }

    /*
     * @testName: testGetColumnClassName
     * 
     * @assertion: The ResultSetMetaData provides information about the types
     * and properties of the columns in a ResultSet object. (See section 27.1 of
     * JDBC 2.0 API Reference & Tutorial 2nd edition)
     * 
     * A driver must provide full support for DatabaseMetaData and
     * ResultSetMetaData. This implies that all of the methods in the
     * ResultSetMetaData interface must be implemented and must behave as
     * specified in the JDBC 1.0 and 2.0 specifications. None of the methods in
     * DatabaseMetaData and ResultSetMetaData may throw an exception because
     * they are not implemented. (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition (J2EE) Specification v1.2)
     * 
     * The getColumnClassName(int colindex) method returns a String object
     * representing the fully qualified name of the Java class to which a value
     * in the designated column will be mapped. (See section 27.3 of JDBC 2.0
     * API Reference & Tutorial 2nd edition)
     * 
     * @test_Strategy: Get the ResultSetMetaData object from the corresponding
     * ResultSet by using the ResultSet's getMetaData method.Call the
     * getColumnClassName(int colindex) method.It should return a String object.
     */
    @Test
    public void testGetColumnClassName() throws Exception
    {
	try
	{
	    // invoke on the getColumnClassName(int column)
	    logMsg("Calling getColumnClassName on ResultSetMetadata");
	    String sRetValue = rsmd.getColumnClassName(1);
	    if (sRetValue == null)
	    {
		logMsg("getColumnClassName method does not returns the fully-qualified name of the class");
	    }
	    else
	    {
		logMsg("getColumnClassName method returns:  " + sRetValue);
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getColumnClassName is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getColumnClassName is Failed!", e);
	}
    }

    /* cleanup */
    @AfterClass
    public static void cleanup() throws Exception
    {
	try
	{
	    stmt.close();
	    // Close the database
	    // dbSch.destroyData(coffeeCon);
	    dbSch.dbUnConnect(coffeeCon);

	    /*
	     * if(coffeeCon == null) logMsg("coffeeCon returns null value");
	     * else coffeeCon.close();
	     */

	    logMsg("Cleanup ok;");
	}
	catch (Exception e)
	{
	    logErr("An error occurred while closing the database connection");
	}
    }
}
